library(dplyr)
library(magrittr)
library(tidyr)
library(ggplot2)

dat <- rio::import("data/LandCover_GRID_CELL_v9_reduced_notpanel.dta")

country_dat <- rio::import("data/Demo_book_country_3.dta")

p1 <- ggplot(dat, aes(x = predallports53_100km)) +
  geom_histogram(aes(y = stat(count)/sum(stat(count))),
                 bins = 76, color = "black", fill = "white") +
  labs(y = "", x = "Grid-cells") +
  scale_x_continuous(breaks = seq(0, 40, 10)) + 
  theme(panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.line = element_line(color = "black"),
        axis.text = element_text(size = 14), 
        plot.margin = margin(1, 1, 1, 0.25, "cm"),
        axis.title.x = element_text(face = 'italic', size = 14, vjust = -5))

p2 <- ggplot(country_dat, aes(x = predallports53_100km)) +
  geom_histogram(aes(y = stat(count)/sum(stat(count))),
                 bins = 48, color = "black", fill = "white") +
  labs(y = "", x = "States") +
  scale_x_continuous(breaks = seq(0, 20, 5)) + 
  theme(panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.line = element_line(color = "black"),
        axis.text = element_text(size = 14), 
        plot.margin = margin(1, 1, 1, 0.25, "cm"),
        axis.title.x = element_text(face = 'italic', size = 14, vjust = -5))

grid <- ggpubr::ggarrange(p1, p2, nrow = 1)
ggsave(grid, file = "output/figure_4_8.tiff", dpi = 300, width = 8.5, height = 5.5)
